feat: v0.6.0 - source_path param, stress_test error detail, docs#2
feat: v0.6.0 - source_path param, stress_test error detail, docs#2SummerOneTwo merged 2 commits intomasterfrom
Conversation
- Add source_path parameter to all build tools (solution_build, generator_build, validator_build, checker_build, interactor_build) as alternative to passing full source code via code parameter - Add encoding fallback (UTF-8 -> latin-1) for source_path files - Add include_dirs support so relative includes work with source_path - Enhance stress_test_run error messages with seed, cmd_args, stdout, stderr, last_input for easier debugging - Distinguish generator failure modes (timeout/empty output/crash) with mode-specific hints - Document generator_args protocol and n_max parameter relationship - Add effective_n_max to stress_test_run success result - Add problem directory structure docs to CLAUDE.md - Bump version to 0.6.0
6b531ce to
d48c121
Compare
There was a problem hiding this comment.
Pull request overview
This PR releases v0.6.0 by adding source_path support across build tools, improving stress_test_run generator failure diagnostics, and updating documentation/versioning.
Changes:
- Add
source_path(optional) to build tools, with encoding fallback and include-dir support for relative#include. - Enhance
stress_test_rungenerator failure reporting (seed/cmd_args/stdout/stderr/last_input) and exposeeffective_n_maxon success. - Update docs (generator_args protocol, n_max semantics, problem directory layout) and bump version to 0.6.0.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Updates locked editable package version entry. |
| src/autocode_mcp/tools/validator.py | Adds source_path input and include-dir support for validator build. |
| src/autocode_mcp/tools/stress_test.py | Improves generator error classification/details; returns effective_n_max. |
| src/autocode_mcp/tools/solution.py | Adds source_path input and include-dir support for solution builds. |
| src/autocode_mcp/tools/mixins.py | Extends build mixin to forward include_dirs into compilation. |
| src/autocode_mcp/tools/interactor.py | Adds source_path input and include-dir support for interactor build. |
| src/autocode_mcp/tools/generator.py | Adds source_path input and include-dir support for generator build. |
| src/autocode_mcp/tools/checker.py | Adds source_path input and include-dir support for checker build. |
| pyproject.toml | Bumps project version to 0.6.0. |
| CLAUDE.md | Documents problem directory structure and adds problem_validate in tool list. |
| CHANGELOG.md | Adds 0.6.0 release notes describing new features/improvements. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ### Features | ||
|
|
||
| - **source_path 参数**: 所有构建工具(solution_build, generator_build, validator_build, checker_build, interactor_build)新增 `source_path` 参数,可直接指定源文件路径,无需传入完整源码字符串。`code` 参数不再为必填,与 `source_path` 二选一。 | ||
| - **source_path 编码回退**: 自动处理非 UTF-8 编码的源文件(如 GBK),先尝试 UTF-8 读取,失败后回退到 latin-1。 |
There was a problem hiding this comment.
这里举例写“如 GBK”,但实现仅做 UTF-8 读取失败后回退 latin-1;latin-1 并不能正确解码 GBK(只是不会抛解码异常),可能导致源码内容乱码。建议要么实现真正的 GBK/自动检测(如优先尝试 gbk/cp936,或引入 charset 检测),要么把文档表述改为“回退到 latin-1(宽松解码)”而不暗示支持 GBK。
| - **source_path 编码回退**: 自动处理非 UTF-8 编码的源文件(如 GBK),先尝试 UTF-8 读取,失败后回退到 latin-1。 | |
| - **source_path 编码回退**: 自动处理非 UTF-8 编码的源文件,先尝试 UTF-8 读取,失败后回退到 latin-1(宽松解码)。 |
| }, | ||
| }, | ||
| "required": ["problem_dir", "solution_type", "code"], | ||
| "required": ["problem_dir", "solution_type"], |
There was a problem hiding this comment.
当前 input_schema 只要求 problem_dir,但 execute() 实际要求必须提供 code 或 source_path(二选一)。这会让 MCP client 依据 schema 生成/校验参数时遗漏必填字段。建议在 schema 增加 anyOf/oneOf 来约束至少提供一个(例如 anyOf: [{required:["code"]},{required:["source_path"]}]),同时保留 source_path 优先级逻辑。
| "required": ["problem_dir", "solution_type"], | |
| "required": ["problem_dir", "solution_type"], | |
| "anyOf": [ | |
| {"required": ["code"]}, | |
| {"required": ["source_path"]}, | |
| ], |
| }, | ||
| }, | ||
| "required": ["problem_dir", "code"], | ||
| "required": ["problem_dir"], |
There was a problem hiding this comment.
当前 input_schema 只要求 problem_dir,但 execute() 实际要求必须提供 code 或 source_path(二选一)。这会导致 client 依据 schema 生成/校验参数时可能遗漏必填字段。建议在 schema 增加 anyOf/oneOf 来约束至少提供一个(例如 anyOf: [{required:["code"]},{required:["source_path"]}])。
| "required": ["problem_dir"], | |
| "required": ["problem_dir"], | |
| "anyOf": [ | |
| {"required": ["code"]}, | |
| {"required": ["source_path"]}, | |
| ], |
| with open(input_path) as f: | ||
| input_data = f.read() | ||
| last_input = input_data |
There was a problem hiding this comment.
这里读取 input.txt 时未指定 encoding,依赖系统默认编码;但 _generate_input 写入时固定使用 UTF-8。非 UTF-8 默认环境下可能出现解码异常或读到错误内容。建议读取时也显式指定 encoding="utf-8"(与写入保持一致)。
| # 解析源代码:source_path 优先于 code | ||
| source_dir = None | ||
| if source_path: | ||
| if not os.path.isabs(source_path): | ||
| source_path = os.path.join(problem_dir, source_path) | ||
| if not os.path.exists(source_path): | ||
| return ToolResult.fail(f"Source file not found: {source_path}") | ||
| try: | ||
| with open(source_path, encoding="utf-8") as f: | ||
| code = f.read() | ||
| except UnicodeDecodeError: | ||
| try: | ||
| with open(source_path, encoding="latin-1") as f: | ||
| code = f.read() | ||
| except Exception as e: | ||
| return ToolResult.fail(f"Failed to read source file: {e}") | ||
| source_dir = os.path.dirname(os.path.abspath(source_path)) |
There was a problem hiding this comment.
新增的 source_path 参数(含相对路径解析 + include_dirs 注入 + 编码回退)目前在 tests/test_tools 下没有覆盖:现有工具测试都只通过 code 字符串调用 build。建议补充至少一个用例:将源码写到临时文件后通过 source_path 调用,并验证包含相对 #include 的场景能成功编译。
| stderr=gen_result.get("stderr", ""), | ||
| stdout=gen_result.get("stdout", ""), | ||
| cmd_args=gen_result.get("cmd_args", []), | ||
| last_input=last_input, |
There was a problem hiding this comment.
这里增强了 generator 失败时返回的诊断字段(seed/cmd_args/stdout/stderr/last_input)以及成功时的 effective_n_max,但 tests/test_tools/test_stress_test.py 目前只覆盖“通过/缺少生成器”等路径,没有断言这些新增字段是否按预期返回。建议补充一个让 generator 超时/空输出/崩溃的用例,验证错误类型提示与 data 字段完整性。
| last_input=last_input, | |
| last_input=gen_result.get("last_input", last_input), |
| }, | ||
| }, | ||
| "required": ["problem_dir", "code"], | ||
| "required": ["problem_dir"], |
There was a problem hiding this comment.
当前 input_schema 只要求 problem_dir,但 execute() 实际要求必须提供 code 或 source_path(二选一)。建议在 schema 增加 anyOf/oneOf 来约束至少提供一个,避免 client 按 schema 调用时得到运行期报错。
| "required": ["problem_dir"], | |
| "required": ["problem_dir"], | |
| "anyOf": [ | |
| {"required": ["code"]}, | |
| {"required": ["source_path"]}, | |
| ], |
| }, | ||
| }, | ||
| "required": ["problem_dir", "code"], | ||
| "required": ["problem_dir"], |
There was a problem hiding this comment.
当前 input_schema 只要求 problem_dir,但 execute() 实际要求必须提供 code 或 source_path(二选一)。建议在 schema 增加 anyOf/oneOf 来约束至少提供一个,避免 client 按 schema 调用时参数不完整。
| "required": ["problem_dir"], | |
| "required": ["problem_dir"], | |
| "anyOf": [ | |
| {"required": ["code"]}, | |
| {"required": ["source_path"]}, | |
| ], |
| }, | ||
| }, | ||
| "required": ["problem_dir", "code"], | ||
| "required": ["problem_dir"], |
There was a problem hiding this comment.
当前 input_schema 只要求 problem_dir,但 execute() 实际要求必须提供 code 或 source_path(二选一)。建议在 schema 增加 anyOf/oneOf 来约束至少提供一个,避免 client 依据 schema 调用时遗漏参数。
| "required": ["problem_dir"], | |
| "required": ["problem_dir"], | |
| "anyOf": [ | |
| {"required": ["code"]}, | |
| {"required": ["source_path"]}, | |
| ], |
- Add anyOf to 5 build tool schemas enforcing code/source_path requirement - Fix CHANGELOG: remove misleading GBK example for latin-1 fallback - Add encoding="utf-8" to stress_test.py file reads - Add tests for source_path (success, not found, neither provided) - Add test for stress_test generator failure diagnostics
Summary
source_path参数,可直接指定源文件路径,无需传入完整源码字符串。支持编码回退(UTF-8 → latin-1)和相对 include 路径。Changes
Test plan
uv run pytest tests/ -q— 176 passeduvx ruff check .— All checks passed